package com.jzmy.employment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.plugins.Page;
import com.jzmy.employment.dao.ApplicationRecordDao;
import com.jzmy.employment.entity.ApplicationRecord;
import com.jzmy.employment.entity.vo.ApplicationRecordVo;
import com.jzmy.employment.service.ApplicationRecordService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 
 * <pre>
 * 应聘记录
 * </pre>
 */
@Service
public class ApplicationRecordServiceImpl extends ServiceImpl<ApplicationRecordDao, ApplicationRecord> implements ApplicationRecordService {

    public Page<ApplicationRecordVo> selectListPage(int current, int number, Map map) {

        // 新建分页
        Page<ApplicationRecordVo> page = new Page<ApplicationRecordVo>(current, number);

        return page.setRecords(this.baseMapper.applicationRecordDyGetList(page,map));

    }

    @Override
    public ApplicationRecord findOneByKv(Object... params) {
        return getOne(this.convertToEntityWrapper(params));
    }

    private QueryWrapper<ApplicationRecord> convertToEntityWrapper(Object... params) {
        QueryWrapper<ApplicationRecord> ew = new QueryWrapper<>();
        if (params == null) {
            return ew;
        }
        for (int i = 0; i < params.length; i++) {
            if (i % 2 == 1 && params[i] != null && StringUtils.isNotBlank(params[i].toString())) {
                if(String.valueOf(params[i - 1]).equals("name")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("file_name")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("title")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else if(String.valueOf(params[i - 1]).equals("introduce")){
                    ew.like((String) params[i - 1], params[i].toString());
                }else{
                    ew.eq((String) params[i - 1], params[i].toString());
                }
            }
        }
        return ew;
    }
}
